package org.hako.recite.word.words.impl;

import java.util.List;
import org.hako.recite.word.model.Word;
import org.hako.recite.word.words.IndexHandler;
import org.hako.recite.word.words.WordSet;

/**
 * Default implement of {@link WordSet}. Use list to store word.
 * 
 * @since 0.4.0
 * @author <a href="mailto:xnnyygn@gmail.com">xnnyygn</a>
 * 
 */
public class DefaultWordSet implements WordSet {

	private List<Word> words;
	private IndexHandler indexHandler;

	/**
	 * Create
	 * 
	 * @param words
	 */
	public DefaultWordSet(List<Word> words) {
		this(words, new DirectIndexHandler());
	}

	/**
	 * Create
	 * 
	 * @param words
	 * @param random
	 */
	public DefaultWordSet(List<Word> words, IndexHandler indexHandler) {
		super();
		this.words = words;
		this.indexHandler = indexHandler;
	}

	@Override
	public String get(int fieldIndex, int wordIndex) {
		return words.get(indexHandler.get(wordIndex)).get(fieldIndex);
	}

	@Override
	public int size() {
		return words.size();
	}
}
